{$asmmode att}

function InterLockedDecrement (var Target: longint) : longint; assembler;
asm
{$ifdef REGCALL}
	movl    $-1,%edx
	xchgl   %edx,%eax
{$else}
	movl    Target, %edx
	movl    $-1, %eax
{$endif}
	lock
	xaddl   %eax, (%edx)
	decl    %eax
end;


function InterLockedIncrement (var Target: longint) : longint; assembler;
asm
{$ifdef REGCALL}
	movl    $1,%edx
	xchgl   %edx,%eax
{$else}
	movl    Target, %edx
	movl    $1, %eax
{$endif}
	lock
	xaddl   %eax, (%edx)
	incl    %eax
end;


function InterLockedExchange (var Target: longint;Source : longint) : longint; assembler;
asm
{$ifdef REGCALL}
	xchgl   (%eax),%edx
	movl    %edx,%eax
{$else}
	movl    Target,%ecx
	movl    Source,%eax
	xchgl   (%ecx),%eax
{$endif}
end;


function InterLockedExchangeAdd (var Target: longint;Source : longint) : longint; assembler;
asm
{$ifdef REGCALL}
	xchgl   %eax,%edx
{$else}
	movl    Target,%edx
	movl    Source,%eax
{$endif}
	lock
	xaddl   %eax, (%edx)
end;


function InterlockedCompareExchange(var Target: longint; NewValue: longint; Comperand: longint): longint; assembler;
asm
{$ifdef REGCALL}
	xchgl   %eax,%ecx
{$else}
	movl    Target,%ecx
	movl    NewValue,%edx
	movl    Comperand,%eax
{$endif}
	lock
	cmpxchgl   %edx, (%ecx)
end;